package com.example.mdc.logback.module.controller;

import com.example.mdc.logback.common.resp.ResultResponse;
import com.example.mdc.logback.module.enitity.Balance;
import com.example.mdc.logback.module.service.BalanceService;
import org.springframework.web.bind.annotation.*;

/**
 * @author:      liu_pc
 * Date:        2023/8/25
 * Description: 余额Controller
 * Version:     1.0
 */
@RequestMapping("balances")
@RestController
public class BalanceController {

    private final BalanceService balanceService;

    public BalanceController(BalanceService balanceService) {
        this.balanceService = balanceService;
    }

    /**
     * 新增余额信息
     *
     * @param balance 余额信息
     */
    @PostMapping
    public ResultResponse<?> addBalance(@RequestBody Balance balance) {
        return balanceService.addBalance(balance);
    }

    @DeleteMapping("/{id}")
    public void deleteBalance(@PathVariable String id) {
        balanceService.deleteBalance(id);
    }

    @PutMapping("/{id}")
    public void updateBalance(@PathVariable String id, @RequestBody Balance balance) {
        balance.setId(id);
        balanceService.updateBalance(balance);
    }
}
